package samples.java.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

public class DbHelperSamples {

    public static void main(String[] args) {

        try {
            ResultSet domainRs = DbHelper.executeQuery("select * from application");
            while (domainRs.next()) {
                System.out.println("code: " + domainRs.getString("code") + " name: " + domainRs.getString("name")
                        + " remark: " + domainRs.getString("remark")
                        + " createBy: " + domainRs.getString("created_by")
                        + " updateBy: " + domainRs.getString("updated_by"));
            }

            int deleteRowCount = DbHelper.executeNonQuery("delete from application");
            System.out.println("delete application row count:" + deleteRowCount);

            final String insertSql = "insert into application (code, name, remark, created_by, updated_by, created_time, updated_time) " +
                    "values (?, ?, ?, ?, ?, ?, ?)";
            int insertRowCount = DbHelper.executeNonQuery(insertSql, "code002", "name002", "remark002", "system", "system", new Date(), new Date());
            System.out.println("insert application row count: " + insertRowCount);

            domainRs = DbHelper.executeQuery("select * from application");
            while (domainRs.next()) {
                System.out.println("code: " + domainRs.getString("code") + " name: " + domainRs.getString("name")
                        + " remark: " + domainRs.getString("remark")
                        + " createBy: " + domainRs.getString("created_by")
                        + " updateBy: " + domainRs.getString("updated_by"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
